﻿namespace PerpetuumSoft.InstrumentationPDA
{
    using PerpetuumSoft.InstrumentationPDA.Mathematics;
    using System;
    using System.Drawing;

    public class Thermometer : LinearControl
    {
        private Color liquidColor = Color.Red;
        private Color tankColor = Color.Gray;

        private void DrawActiveBar(Graphics g)
        {
            Vector location = new Vector(base.Direction, base.StartPoint[base.Direction], base.CenterLine - (base.BarWidth / 2));
            Vector size = new Vector(base.Direction, this.ToPoint(base.Value)[base.Direction] - base.StartPoint[base.Direction], base.BarWidth);
            VectorRectangle rectangle = new VectorRectangle(location, size);
            g.FillRectangle(new SolidBrush(this.LiquidColor), rectangle.PositiveRectangle().Round());
        }

        protected override void DrawDynamic(Graphics g)
        {
            this.DrawActiveBar(g);
            base.DrawDynamic(g);
        }

        private void DrawInactiveBar(Graphics g)
        {
            decimal num;
            Vector location = new Vector(base.Direction, base.StartPoint[base.Direction], base.CenterLine - (base.BarWidth / 2));
            Vector size = new Vector(base.Direction, base.EndPoint[base.Direction] - base.StartPoint[base.Direction], base.BarWidth);
            VectorRectangle rectangle = new VectorRectangle(location, size);
            g.FillRectangle(new SolidBrush(this.TankColor), rectangle.PositiveRectangle().Round());
            if (base.ReverseScale)
            {
                num = -((decimal) (Math.Sqrt(3.0) / 2.0));
            }
            else
            {
                num = (decimal) (Math.Sqrt(3.0) / 2.0);
            }
            //Vector vector3 = new Vector(Direction, StartPoint[Direction] - (BarWidth * decimal.op_Increment(num)), base.StartPoint.GetSecondaryValue(base.Direction) - base.BarWidth);
            Vector vector3 = new Vector(Direction, StartPoint[Direction] - (BarWidth * (num++)), base.StartPoint.GetSecondaryValue(base.Direction) - base.BarWidth);
            Vector vector4 = new Vector(base.Direction, base.EndPoint[base.Direction] - (base.BarWidth / 2), base.CenterLine - (base.BarWidth / 2));
            VectorRectangle rectangle3 = new VectorRectangle(vector3, new Size(base.Round(2 * base.BarWidth), base.Round(2 * base.BarWidth)));
            g.FillEllipse(new SolidBrush(this.LiquidColor), rectangle3.PositiveRectangle().Round());
            VectorRectangle rectangle5 = new VectorRectangle(vector4, new Size(base.BarWidth - 1, base.BarWidth - 1));
            g.FillEllipse(new SolidBrush(this.TankColor), rectangle5.PositiveRectangle().Round());
        }

        protected override void DrawStatic(Graphics g)
        {
            this.DrawInactiveBar(g);
            base.DrawStatic(g);
        }

        protected override Size DefaultControlSize
        {
            get
            {
                return new Size(0xe0, 0x70);
            }
        }

        public Color LiquidColor
        {
            get
            {
                return this.liquidColor;
            }
            set
            {
                if (this.liquidColor != value)
                {
                    this.liquidColor = value;
                    base.InvalidateStatic();
                }
            }
        }

        public Color TankColor
        {
            get
            {
                return this.tankColor;
            }
            set
            {
                if (this.tankColor != value)
                {
                    this.tankColor = value;
                    base.InvalidateStatic();
                }
            }
        }
    }
}

